import {fileURLToPath, URL} from 'node:url'

import {defineConfig, loadEnv} from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import vueDevTools from 'vite-plugin-vue-devtools'
import * as path from "path";
// https://vite.dev/config/
export default ({mode}: { mode: string }) => {
  // 加载当前模式的环境变量
  const env = loadEnv(mode, process.cwd())

  return defineConfig({
    plugins: [
      vue(),
      vueJsx(),
      vueDevTools(),
    ],
    define: {
      //配置全局调用查询 process.env直接调用env中的环境变量
      'process.env': env,
    },
    resolve: {
      alias: {
        '@': path.resolve(__dirname, './src'),
        '~views': path.resolve(__dirname, './src/views')
      },
    },
    server: {
      open: true,
      port: 3000,
    },
  })
}


